<?php
$apiKey = "";
$task = $_GET['task'];
$taskID = $task;
$url = "https://api.tripo3d.ai/v2/openapi/task/$taskID";

// 设置请求头
$headers = [
    'Authorization: Bearer '. $apiKey
];
//等10秒
//sleep(10);
// 创建一个cURL资源
$ch = curl_init();

// 设置URL和其他适当的选项
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// 执行请求并获取响应
$response = curl_exec($ch);

// 检查是否有错误发生
if ($response === false) {
    $error = curl_error($ch);
    curl_close($ch);
    throw new Exception("cURL error: ". $error);
}

// 获取HTTP状态码
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// 关闭cURL资源
curl_close($ch);

if ($httpStatus!= 200) {
    throw new Exception("HTTP error! status: $httpStatus, info: ". substr($response, 0, 100));
}

// 将响应解析为JSON数据（假设响应是JSON格式）
$data = json_decode($response, true);

// 跳转到指定的链接
//var_dump($data);
@$redirectUrl = $data['data']['output']['model'];
if(isset($redirectUrl)){
    header("Location: $redirectUrl");
}else{
    header("Refresh: 0");
}

exit;
?>